app.controller("oneToOnellController",function($scope, $http, $filter){
        $("#createclass").change(function () {
            var class_id=$(this).val();
            $.ajax({
                type:"POST",
                url:"/OA/classsubject/find",
                data:{class_id:class_id},
                dataType:"json",
                success:function (result){
                    console.log(result)
                    $("#subjectname").html("");
                    for (var i = 0; i < result.data.length; i++) {
                        $("#subjectname").append('<option value='+result.data[i].id+'>'+result.data[i].subject_name+'：'+result.data[i].staff_name+'</option>')
                    };
                }
            })
        })
    $scope.save=function () {
          var class_id=$("#createclass").find("option:selected").val();
          var class_subject_id=$("#subjectname").find("option:selected").val();
          var out_entry=$("#starttime").val();
              date_departure=out_entry.replace(/-/g,'/');
              date_departure=new Date(date_departure);
              date_departure=date_departure.getTime();
              class_date=$filter("date")(date_departure, "yyyy-MM-dd");
          var class_time_have=$("#haveclockpicker").val();
          var class_time_over=$("#overclockpicker").val();
        //时间比较（yyyy-MM-dd HH:mm:ss）
         function compareTime(startTime,endTime) {
            var startTimes = startTime.substring(0, 10).split('-');
            var endTimes = endTime.substring(0, 10).split('-');
            startTime = startTimes[1] + '-' + startTimes[2] + '-' + startTimes[0] + ' ' + startTime.substring(10, 19);
            endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);
            var thisResult = (Date.parse(endTime) - Date.parse(startTime)) / 3600 / 1000;
            if (thisResult < 0) {
                alert("开始时间小于结束时间,请重新填写！");
                return false
            }else if (thisResult == 0) {
                alert("开始时间等于结束时间,请重新填写！");
                return false
            } else {
                return '异常';
            }
        }
          class_time_have=class_time_have+":00";
          class_time_over=class_time_over+":00";
          var start_time=class_date+" "+class_time_have;
          var end_time=class_date+" "+class_time_over;
          var veify=compareTime(start_time,end_time);
            if(veify==false || veify=="异常"){
                return
            }
          $http({
              method: 'POST',
              url: '/OA/classclazz/create',
              data:$.param({class_id:class_id,class_subject_id:class_subject_id,class_date:class_date,class_time_have:class_time_have,class_time_over:class_time_over}),
              headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
          }).success(function (response) {
              if(response.ok==true){
                  $("#myModal").modal("hide");
                  setTimeout(function () {
                      window.location.reload()
                  },600)
              }else if(response.ok==false){
                  alert(response.message);
              }
          })
      }
       // 班课排课
          $http({
              method: 'GET',
              url: '/OA/classclazz/list',
              headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
          }).success(function (response) {
                $scope.classdatas=response.data;
                console.log($scope.classdatas)
              $scope.delete = function($index){
                  if ($index>=0) {
                      if(confirm("是否删除"+$scope.classdatas[$index].number+"课次的课程！") ){
                          //将需要删除的卡号传给后台  2017/7/10
                          $http({
                              method: 'POST',
                              url: '/OA/classclazz/delete',
                              data: $.param({id:$scope.classdatas[$index].id}),
                              headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                          }).success(function (result) {
                              if (result.ok==true) {
                                  $scope.classdatas.splice($index,1);
                                  window.location.reload()
                              }
                          }).error(function(result){
                              alert("删除失败")
                          })
                      }
                  };
              }
              // 编辑
              $scope.prod={};
              $scope.edit = function($index){

              }
          })
    // 日历时间调用
    $(function () {
        $('#calendar').calendar({
            ifSwitch: true, // 是否切换月份
            hoverDate: true, // hover是否显示当天信息
            backToday: true // 是否返回当天
        });
        var  item=$(".calendar-date>.item");
        item.click(function(){
            index=$(this).index();
            item.attr("class","item item-curMonth");
            $(this).attr("class","item item-curDay");
            dataTime=item.eq(index).attr('data');
            dataTime=dataTime.split('');
            dataTime.splice(4,0,'/');
            dataTime.splice(7,0,'/');
            dataTime=dataTime.join('');
            clickTime=new Date(dataTime);
            unixTime=clickTime.getTime();
            $scope.date = $filter("date")(unixTime, "yyyy-MM-dd");
            var class_id=$("#createclasshtml").find("option:selected").val();
            $http({
                method: 'POST',
                url: '/OA/classclazz/list',
                data:$.param({class_date:$scope.date,class_id:class_id}),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).success(function (response) {
                $scope.classdatas=response.data;
                console.log($scope.classdatas)
            })
        })
        $("#createclasshtml").change(function () {
            var class_id=$(this).val();
            $http({
                method: 'POST',
                url: '/OA/classclazz/list',
                data:$.param({class_date:$scope.date,class_id:class_id}),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).success(function (response) {
                $scope.classdatas=response.data;
                console.log($scope.classdatas)
            })
        })

    });
})